package cn.iocoder.yudao.module.engine.util;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class EngineStrUtils {

    public static List<String> getContainsMultiValues(List<String> arr, String str) {
        final List<String> multiValues = getMultiValue(str);
        if (CollUtil.isEmpty(multiValues)) {
            return new ArrayList<>();
        }

        return arr.stream().filter(s -> multiValues.contains(s)).toList();
    }

    public static boolean containsMultiValues(List<String> arr, String str) {
        final List<String> multiValues = getMultiValue(str);
        if (CollUtil.isEmpty(multiValues)) {
            return false;
        }

        return arr.stream().anyMatch(s -> multiValues.contains(s));
    }

    public static List<String> getMultiValue(String str) {
        if (StrUtil.isEmpty(str)) {
            return null;
        }

        final String[] multiValues = str.split("\\|");
        if (multiValues == null || multiValues.length == 0) {
            return new ArrayList<>();
        }

        return Arrays.asList(multiValues);
    }

    public static void main(String[] args) {
        String str = "a|b|c";
        String[] split = str.split("\\|");
        System.out.println(Arrays.asList(split));

        System.out.println(RandomUtil.randomInt(0, 1));
    }

}
